package com.laolu.icon.utils;

import com.laolu.icon.entity.IconInfo;

import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

public class MyBackup {
	
	public void backup(String path) throws Exception {
		File file = new File(path);
		String fileName;
		if (file.isFile()) {
			fileName = file.getAbsolutePath();
		} else {
			String dateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
			fileName = file.getAbsolutePath() + File.separator + dateTime + ".txt";
		}
		MyIcon myIcon = new MyIcon();
		MyFileWrite write = new MyFileWrite(fileName);
		List<IconInfo> desktopIconInfo = myIcon.getDesktopIconInfo();
		try (write) {
			write.writeList(desktopIconInfo);
		}
	}
}
